package com.woniu.service.impl;

import com.woniu.been.entity.Courses;
import com.woniu.been.entity.UserCourse;
import com.woniu.been.entity.UserOrders;
import com.woniu.mapper.UserCourseMapper;
import com.woniu.service.UserCourseServicce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class UserCourseImpl implements UserCourseServicce {
    @Autowired
    UserCourseMapper usercoursemapper;

    @Override
    public Map<String,Object> isOrder(UserCourse userCourse) {
        // 根据courseid查出是否有
        UserCourse usercourse= usercoursemapper.seletcCourseByUserID(userCourse);
        //根据courid 查出价格
        Courses courses = usercoursemapper.findCourseById(userCourse);
        Map<String,Object> map=new HashMap<>();
        map.put("isorder",usercourse);
        map.put("courses",courses);
        return map;
    }

    @Override
    public   Map<String,Object> getIds(UserOrders userOrders) {

        List<UserOrders> ids = usercoursemapper.getIds(userOrders);
        List<Integer> list = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();
        for (UserOrders item:ids ) {
            list.add(item.getOrderId());
            list2.add(item.getCourseId());
        }

        // 转为字符串
        String orderIds = list.stream()
                .map(String::valueOf)
                .collect(Collectors.joining(","));
        String courseIds = list2.stream()
                .map(String::valueOf)
                .collect(Collectors.joining(","));

        System.out.println(list+"-----"+orderIds);
        Map<String,Object> maps = new HashMap<>();
        maps.put("orderIds",orderIds);
        maps.put("courseIds",courseIds);
        return maps;
    }
}
